package PA::dbwrap;

use strict;
use warnings;
use DBI;
use Carp;
use lib '/home/homer/ju/jussimik/.laka/pokeralyzer/';
use PA::config;

BEGIN {
	our %config = PA::config::get_settings();
	our $dbh = DBI->connect("dbi:mysql:" . "dbname=" .
		$config{mysql_db} . ";host=" . $config{mysql_host},
		$config{mysql_user}, $config{mysql_pass})
		or croak "Couldn't connect to database: " . DBI->errstr;
}

our($dbh, %config);

sub get_dbh {
	if(!(defined($dbh) && $dbh->ping)) {
		unless($dbh = DBI->connect("dbi:mysql:" . "dbname=" .
			$config{mysql_db} . ";host=" . $config{mysql_host},
			$config{mysql_user}, $config{mysql_pass})) {
				$dbh = undef;
                die "Couldn't connect to MySQL-database: " . DBI->errstr;
		}
	}
	return $dbh;
}

1;

